const tool = require('ToolUtil');
const GAMEID = tool.GAMEID;
cc.Class({
    extends: cc.Component,

    properties: {
        loadingImg: cc.Sprite,
        windowLayer: cc.Node,
        windowShadow: cc.Node,
        _changeSceneName: ''
    },


    /**
     * 初始化全部控件，然后再跳转
     */
    init: function () {
        // var data = {
        //     "id": 5099,
        //     "name": "西马",
        //     "sex": 1,
        //     "silver": 213,
        //     "gold": 0,
        //     "head": "http://thirdwx.qlogo.cn/mmopen/vi_32/7KjPUfv6S5p2LgtwP1ohnyVukKuv5fhPPsFzILYj4VmRhooYp518vQ75EicClsNTngx7jRWUT0MkKriaP4P8DTbw/0",
        //     "matchItem": [{
        //         "matchName": "1",
        //         "ownerId": "22",
        //         "guildName": "彭梦佳",
        //         "matchCode": "11322455",
        //         "gameId": "5",
        //         "ruleType": "{\"bankertype\":\"0\",\"hutype\":\"0\",\"piao\":true}",
        //         "gameCnt": "8",
        //         "oldMatchCode": "0",
        //         "oldDynamicCode": "0",
        //         "oldId": "1793"
        //     }, {
        //         "gameId": "3",
        //         "guildName": "测试CCCCCCCC",
        //         "matchCode": "22449233",
        //         "oldMatchCode": "38433662",
        //         "ruleType": "{\"turn\":10,\"playnums\":3,\"isRandom\":true,\"ruletype\":2494,\"readytimeout\":\"60\",\"optimeout\":0}",
        //         "gameCnt": "10",
        //         "matchName": "新版跑得快111111111111",
        //         "ownerId": "3004",
        //         "oldDynamicCode": "95436567",
        //         "oldId": "2968"
        //     }, {
        //         "matchName": "发送到",
        //         "ownerId": "23",
        //         "guildName": "彭梦佳2222",
        //         "matchCode": "34341646",
        //         "gameId": "5",
        //         "ruleType": "{\"bankertype\":\"0\",\"hutype\":\"0\",\"piao\":false}",
        //         "gameCnt": "10",
        //         "oldMatchCode": "0",
        //         "oldDynamicCode": "0",
        //         "oldId": "0"
        //     }, {
        //         "matchName": "转转麻将IIII",
        //         "ownerId": "353",
        //         "guildName": "大大大",
        //         "matchCode": "37943364",
        //         "gameId": "4",
        //         "ruleType": "{\"ruleType\":2,\"gameCnt\":8,\"canEatPao\":4100,\"birdCnt\":0}",
        //         "gameCnt": "8",
        //         "oldMatchCode": "37336057",
        //         "oldDynamicCode": "75434636",
        //         "oldId": "290"
        //     }, {
        //         "gameId": "1",
        //         "guildName": "雀友会",
        //         "matchCode": "42781080",
        //         "oldMatchCode": "44288208",
        //         "ruleType": "{\"turn\":8,\"playnums\":4,\"scoretype\":28,\"birdtype\":6,\"gametype\":0,\"hutype\":528,\"isPiao\":false,\"isRandom\":false,\"isKan3Pei\":false,\"readytimeout\":\"15\",\"optimeout\":0}",
        //         "gameCnt": "8",
        //         "matchName": "贰",
        //         "ownerId": "276",
        //         "oldDynamicCode": "24321868",
        //         "oldId": "47"
        //     }, {
        //         "gameId": "3",
        //         "guildName": "雀友会",
        //         "matchCode": "44074265",
        //         "oldMatchCode": "67227367",
        //         "ruleType": "{\"turn\":10,\"playnums\":3,\"isRandom\":false,\"ruletype\":10,\"readytimeout\":\"30\",\"optimeout\":0}",
        //         "gameCnt": "10",
        //         "matchName": "跑得快",
        //         "ownerId": "276",
        //         "oldDynamicCode": "26213047",
        //         "oldId": "47"
        //     }, {
        //         "matchName": "阿拉蕾",
        //         "ownerId": "95",
        //         "guildName": "*嗲嗲习**",
        //         "matchCode": "52329189",
        //         "gameId": "4",
        //         "ruleType": "{\"ruleType\":1,\"gameCnt\":8,\"canEatPao\":72,\"birdCnt\":0}",
        //         "gameCnt": "8",
        //         "oldMatchCode": "90665131",
        //         "oldDynamicCode": "61768421",
        //         "oldId": "2"
        //     }, {
        //         "gameId": "9",
        //         "guildName": "西马的",
        //         "matchCode": "66357148",
        //         "oldMatchCode": "77947741",
        //         "ruleType": "{\"gametype\":0,\"turn\":1,\"ruletype\":7,\"xipoint\":261,\"readytimeout\":90,\"optimeout\":0}",
        //         "gameCnt": "1",
        //         "matchName": "牛",
        //         "ownerId": "275",
        //         "oldDynamicCode": "98725467",
        //         "oldId": "46"
        //     }, {
        //         "gameId": "1",
        //         "guildName": "烟雨笑红尘",
        //         "matchCode": "75120173",
        //         "oldMatchCode": "35482947",
        //         "ruleType": "{\"turn\":8,\"playnums\":3,\"scoretype\":28,\"birdtype\":50,\"gametype\":0,\"hutype\":48,\"isPiao\":false,\"isRandom\":true,\"isKan3Pei\":false,\"readytimeout\":\"0\",\"optimeout\":0}",
        //         "gameCnt": "8",
        //         "matchName": "新长沙麻将2",
        //         "ownerId": "262",
        //         "oldDynamicCode": "97602338",
        //         "oldId": "19"
        //     }, {
        //         "gameId": "1",
        //         "guildName": "测试CCCCCCCC",
        //         "matchCode": "75264287",
        //         "oldMatchCode": "98812772",
        //         "ruleType": "{\"turn\":8,\"playnums\":4,\"scoretype\":0,\"birdtype\":132,\"gametype\":0,\"hutype\":4119,\"isPiao\":false,\"isRandom\":true,\"isKan3Pei\":false,\"readytimeout\":\"0\",\"optimeout\":\"0\"}",
        //         "gameCnt": "8",
        //         "matchName": "BGM",
        //         "ownerId": "3004",
        //         "oldDynamicCode": "13165066",
        //         "oldId": "2968"
        //     }, {
        //         "gameId": "7",
        //         "guildName": "西马的",
        //         "matchCode": "76151467",
        //         "oldMatchCode": "73036712",
        //         "ruleType": "{\"turn\":6,\"playnums\":4,\"isRandom\":false,\"ruletype\":3,\"xipoint\":261,\"readytimeout\":120,\"optimeout\":0}",
        //         "gameCnt": "6",
        //         "matchName": "消操",
        //         "ownerId": "275",
        //         "oldDynamicCode": "53055633",
        //         "oldId": "46"
        //     }],
        //     "way": 1,
        //     "trushName": null,
        //     "Identification": null,
        //     "ip": "::ffff:192.168.0.8",
        //     "ticket": "8b307bd561a04c37bcd920f0d03e037c5099"
        // };

        // //获取用户信息
        // cc.windowManager.showWindowByNameWithDate('loadingwin', '获取用户数据中,请稍等...');


        // if (tool.PlayerManager().m_MySelf == null) {
        //     tool.PlayerManager().newPlayer(data);
        // } else {
        //     tool.PlayerManager().m_MySelf.init(data);
        // }
        // this.changeScene('hall');

        // tool.startlogin({
        //     account: 'otMWCwrzRC3xdkomR6gkT-g-WCcI',
        //     // password: 'E10ADC3949BA59ABBE56E057F20F883E',
        //     type: tool.LOGINTYPE.WX, //类型
        //     gameid: 0,
        //     code: cc.gameVersion
        // }, this.changeScene.bind(this));

        tool.NetManager().initWithRecordData(1,'CgpyZWNvcmRpbmZvEpkBChsICBAEGAAgACiACjgAQABIAFABWABgAGh4cAAQx+wSIhcIrd4FEAAaBueFiueFiiDqBygAMAE4AiIXCP+LAhABGgblvIDmupwg6QcoADACOAEiHQjDyAYQAhoM6YeN5aS05YaN5p2lIOQHKAAwAzgBIiMI2dQGEAMaEuOAkOWkj+mbquWEv+W6l+OAkSDpBygAMAQ4AigB|CglHQU1FU1RBUlQSlAEIAxAHGDciIQgAEAAY6gc4AjgROBM4CDgLOAs4ETgMOA44HTgdOBo4GCIhCAEQABjpBzgIOBA4EjgcOAc4EzgXOBU4FjgdOAQ4EDgdIiEIAhAAGOQHOAU4FTgJOBY4FTgcOBI4DjgZOBs4FTgHOBwiIwgDEAAY6Qc4FzgYOAg4FzgEOBs4DzgDOA44DTgBOBY4BjgG|CglTQ09VVENBUkQSBAgDEAE=|CglTQ0dFVENBUkQSBAgAEAQ=|CglTQ09VVENBUkQSBAgAEAg=|CglTQ0dFVENBUkQSBAgBEA0=|CglTQ09VVENBUkQSBAgBEAQ=|CglTQ0dFVENBUkQSBAgCEAk=|CglTQ09VVENBUkQSBAgCEBY=|CglTQ0dFVENBUkQSBAgDEBw=|CglTQ09VVENBUkQSBAgDEAg=|CglTQ0dFVENBUkQSBAgAEAY=|CglTQ09VVENBUkQSBAgAEA4=|CglTQ0dFVENBUkQSBAgBEAI=|CglTQ09VVENBUkQSBAgBEA0=|CglTQ0dFVENBUkQSBAgCEAI=|CglTQ09VVENBUkQSBAgCEA4=|CglTQ0dFVENBUkQSBAgDEBA=|CglTQ09VVENBUkQSBAgDEBc=|CglTQ0dFVENBUkQSBAgAEA0=|CglTQ09VVENBUkQSBAgAEAs=|CglTQ0dFVENBUkQSBAgBEBI=|CglTQ09VVENB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pTQ1FVRVNURUFUEgwIARACGBwqBAgCEBA=|CgpTQ1FVRVNURUFUEgQIARAA|CgVTQ0VBVBIKCAESBggQEBAYAw==|CglTQ09VVENBUkQSBAgBEAc=|CglTQ0dFVENBUkQSBAgCEAU=|CglTQ09VVENBUkQSBAgCEAc=|CglTQ0dFVENBUkQSBAgDEAs=|CglTQ09VVENBUkQSBAgDEAs=|CglTQ0dFVENBUkQSBAgAEAw=|CglTQ09VVENBUkQSBAgAEAw=|CglTQ0dFVENBUkQSBAgBEBo=|CglTQ09VVENBUkQSBAgBEBo=|CglTQ0dFVENBUkQSBAgCEAU=|CglTQ09VVENBUkQSBAgCEBk=|CglTQ0dFVENBUkQSBAgDEBs=|CglTQ09VVENBUkQSBAgDEBw=|CglTQ0dFVENBUkQSBAgAEBo=|CglTQ09VVENBUkQSBAgAEBo=|CgpTQ1FVRVNURUFUEgYIAhAQGCQ=|CgpTQ1FVRVNURUFUEgQIAhAA|CghTQ0NBTExIVRIuCAIQARgaIgYIBRAFGAMiBggJEAkYASIGCBUQFRgDIgYIGhAYGAIqBggcEBwYAw==|CgtTQ1NIT1dDQVJEUxIeCAAQABgCGBEYGRgEGA0YCxgRGAwYAxgdGB0YGhgY|CgtTQ1NIT1dDQVJEUxIiCAEQABgIGB0YHRgVGAcYFhgXIgYIEhASGAMiBggQEBAYAw==|CgtTQ1NIT1dDQVJEUxIiCAMQABgOGBgYGxgXGBkYGxgNIgYIBhAGGAMiBggPEA8YAw==|CglTQ0JBTEFOQ0USTggHEOCKlQwYAyAAMhUIABD///////////8BGAAgACgAOAAyDAgBEAAYACAAKAA4ADIOCAIQARgBIAEoADAaOAAyDAgDEAAYACAAKAA4AA==', 1);


    },

    changeScene: function (name) {
        cc.windowManager.dismissWindowByName('loadingwin');
        this._changeSceneName = name.toLocaleLowerCase();
        if (this.loadingImg) {
            this.loadingImg.node.runAction(cc.sequence(cc.fadeTo(0.4, 0), cc.callFunc(this.loadOver.bind(this), this)));
        } else {
            this.loadOver();
        }
    },

    loadOver: function () {
        this.loadingImg.node.stopAllActions();
        this.loadingImg.node.active = false;
        if (this._changeSceneName != '') {
            cc.director.loadScene(this._changeSceneName);
        } else {
            cc.director.loadScene('hall');
        }
    },

    // use this for initialization
    onLoad: function () {

        this.windowLayer.active = false;
        this.windowShadow.active = false;
        cc.game.addPersistRootNode(this.windowLayer);

        tool.NetManager().registGameInfo(GAMEID.mj, 'MJScene', 'MJPacket', 'MJAction');


        //窗口
        cc.windowManager = new(require("WindowManager"));
        cc.windowManager.init(this.windowLayer, this.windowShadow);
        cc.windowManager.registerWindow('msgwin', 'MsgWin');
        cc.windowManager.registerWindow('enterwin', 'EnterWin');
        cc.windowManager.registerWindow('loadingwin', 'LoadingWin');


        // // //玩家
        // cc.playerManager = new(require("PlayerManager"));
        // cc.netManager = new(require('NetManager'));


        tool.setTicket(100);


    },

    // 游戏刚开始时
    start() {
        this.init();
    },

    // called every frame
    update: function (dt) {

    }


});